home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / New System Software Extensions / QuickDraw™ GX v1.0ß2 / Sample Code / Graphics Samples / Getting Started with GX (WWDC)ƒ / Getting Started GX - printing.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-14  |  5.4 KB  |  183 lines  |  [TEXT/KAHL]

  1. /**
  2.  --
  3.  --        App:        Getting Started w/QD GX (WWDC)
  4.  -- 
  5.  -- 
  6.  --        Version:    1.0     4/93:    added all of the calls required to support the "Getting 
  7.  --                                    Started with QuickDraw™ GX" session at the WWDC '93     
  8.  --
  9.  --                            8/93:    updated file to work with the ß2 "GXified" interface files
  10.  --
  11.  -- 
  12.  --        File:        Getting Started GX - printing.c
  13.  --
  14.  --
  15.  --        Comments:    This code contains all of the functions required to print the QuickDraw GX shapes we created.
  16.  --                    We use the QuickDraw GX printing method which takes a picture and passes it to the QuickDraw GX 
  17.  --                    printing system. The picture will always contains what is in the front window.
  18.  --
  19.  --                    If QuickDraw GX printing systems has not been installed, the printing menu items in the File
  20.  --                    menu will be dis-abled.
  21.  --
  22.  --
  23.  --        Components:    Getting Started GX - main.c
  24.  --                    Getting Started GX - main.h
  25.  --                    Getting Started GX - shapes.c
  26.  --                    Getting Started GX - printing.c
  27.  --                    Getting Started GX - misc.c
  28.  --                    Getting Started QD GX.π.rsrc
  29.  --
  30.  --                    The file titled: "Getting Started GX - main.c" contains the code required to
  31.  --                    intialize and tear down the QuickDraw GX world, and the event loop.
  32.  --
  33.  --                    The file titled: "Getting Started GX - shapes.c" contains of the code used to 
  34.  --                    create and manipulate the shapes draw into the window.
  35.  --        
  36.  --        
  37.  --        QuickDraw GX
  38.  --        Libraries
  39.  --        Used:        This application uses the following QuickDraw GX library code files:
  40.  --                    "color library.c", "font library.c", "graphics debug library.c",
  41.  --                    "layout library.c", "qd library.c", "shape library.c", 
  42.  --                    "transferMode library.c", and "transform library.c". 
  43.  --        
  44.  --        
  45.  --        Notes:        1) Print this file in landscape for the best results
  46.  --                    2) If you are using THINK C v5.x, I have added THINK markers to navigate the code.
  47.  --                    3) This code was adapted from the "Banana Jr." QuickDraw GX sample.
  48.  --
  49.  --
  50.  --        Author:        Pete "Luke" Alexander
  51.  --                    Developer Technical Support
  52.  --                    AppleLink: DEVSUPPORT
  53.  --
  54.  --        
  55.  --        ©1992 - 1993  Apple Computer, Inc. 
  56.  --        All rights reserved.
  57.  --
  58.  **/
  59.  
  60. #include "PrintingManager.h"
  61. #include "Getting Started GX - main.h"
  62.  
  63.  
  64. /*------ SetUpEditMenuRec ------------------------------------------------------------------------------------*/
  65. //
  66. //    This routine sets up an gxEditMenuRecord which references our edit menu.  This structure
  67. //    is used by the GXJobDefaultFormatDialog and GXJobPrintDialog calls to allow cut, copy, & paste
  68. //    operations from the dialogs.
  69. //
  70. void SetUpEditMenuRec(gxEditMenuRecord *edMenuRec)
  71. {
  72.  
  73.     edMenuRec->editMenuID = mEdit;
  74.     edMenuRec->cutItem = iCut;
  75.     edMenuRec->copyItem = iCopy;
  76.     edMenuRec->pasteItem = iPaste;
  77.     edMenuRec->clearItem = iClear;
  78.     edMenuRec->undoItem = iUndo;
  79. }
  80.  
  81.  
  82. /*------ DoFormat ------------------------------------------------------------------------------------*/
  83. //
  84. //    This routine performs GX's equivalent of the Page Setup (PrStlDialog) call of
  85. //    the old printing architecture.
  86. //
  87. OSErr DoFormat(WindowPtr theWindow, gxDialogResult    *result)
  88. {
  89.     OSErr                err;
  90.     gxEditMenuRecord    edMenuRec;
  91.     gxJob                documentJob;
  92.  
  93.     //
  94.     //    If we have a non-nil WindowPtr, set up our edit menu record and handle the job
  95.     //    format dialog.  Remember to check for errors.
  96.     //
  97.     if (theWindow)
  98.     {
  99.         documentJob = GetDocJob(theWindow);
  100.         SetUpEditMenuRec(&edMenuRec);
  101.         *result = GXJobDefaultFormatDialog(documentJob, &edMenuRec);
  102.     }
  103.     
  104.     return GXGetJobError(documentJob);
  105. }
  106.  
  107.  
  108. /*------ DoPrinting ----------------------------------------------------------------------------------*/
  109. //
  110. //    This routine performs QuickDraw GX's equivalent of the Print gxJob Dialog (PrJobDialog) call of
  111. //    the old printing architecture, and then prints the document if the user wants to.
  112. //
  113. OSErr DoPrinting(WindowPtr theWindow)
  114. {
  115.     OSErr                err = noErr;
  116.     gxDialogResult        result;
  117.     gxEditMenuRecord    edMenuRec;
  118.     gxJob                docJob;
  119.  
  120.  
  121.     //
  122.     //    If we have a non-nil WindowPtr, set up our edit menu record and handle the print
  123.     //    job dialog.  Remember to check for errors.  If no errors occur, and the user clicks
  124.     //  ok, print the window's document.
  125.     //
  126.     if (theWindow)
  127.     {
  128.         docJob = GetDocJob(theWindow);
  129.         
  130.         SetUpEditMenuRec(&edMenuRec);
  131.         result = GXJobPrintDialog(docJob, &edMenuRec);
  132.         err = GXGetJobError(docJob);
  133.                 
  134.         if ((result == gxOKSelected) && !(err))
  135.             err = DoPrintOne(theWindow);
  136.     }
  137.     
  138.     return err;
  139. }
  140.  
  141.  
  142.  
  143. /*------ DoPrintOne ----------------------------------------------------------------------------------*/
  144. //
  145. //    This routine prints one copy of the window's document using whatever job and format
  146. //    is currently attached to it.  (If the window wwere just created and then the user
  147. //    selected Print One w/o first selecting Page Setup…, the system default job and
  148. //    format are stored with this document.
  149. //
  150. OSErr DoPrintOne(WindowPtr theWindow)
  151. {
  152.     OSErr        err = noErr;
  153.     gxJob        documentJob;
  154.     Str255        windowTitle;
  155.  
  156.     //
  157.     //    If we have a non-nil WindowPtr, start the print job, print a page and then finish
  158.     //    the job.  Since we have just a one page document, we don't bother counting pages.
  159.     //    Remember to check those errors!
  160.     //
  161.     if (theWindow)
  162.     {
  163.         documentJob = GetDocJob(theWindow);
  164.         GetWTitle(theWindow, windowTitle);
  165.     
  166.         GXStartJob(documentJob, windowTitle, 1);
  167.         err = GXGetJobError(documentJob);
  168.         
  169.         if (!err)
  170.         {
  171.               GXPrintPage(documentJob, 1,GXGetJobFormat(documentJob, 1), GetDocShape(theWindow));
  172.             err = GXGetJobError(documentJob);
  173.         }
  174.         
  175.         GXFinishJob(documentJob);
  176.         if (!err) err = GXGetJobError(documentJob);
  177.     }
  178.     return err;
  179. }
  180.  
  181.  
  182.  
  183.